﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel;

    public static class FunctionExtend
    {
        public static SelectList ToSelectList(this Enum enumValue)
        {
            var select = from Enum e in Enum.GetValues(enumValue.GetType())
                   select new SelectListItem
                   {
                       Selected = e.Equals(enumValue),
                       Text = e.ToDescription(),
                       Value = e.ToString()
                   };

            return new SelectList(select, "Value", "Text", enumValue.ToString());
        }

        public static string ToDescription(this Enum value)
        {
            var attributes = (DescriptionAttribute[])value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
            return attributes.Length > 0 ? attributes[0].Description : value.ToString();
        }

        public static void AjaxContext(this WebViewPage context)
        {
            bool isAJAX = false;
            try
            {
                isAJAX = bool.Parse(context.Request.QueryString["ajax"]);
            }
            catch
            {
                isAJAX = false;
            }
            if (isAJAX)
                context.Layout = null;
        }


    }
    public static class InitPage
    {
        
    }
